import SpecParams from './core/spec/SpecParams';
const ecdh = require('./core/ecdh');
const Buffer = require('buffer').Buffer;

class AESCrypto {
    private aesAlgo;
    constructor(specParams?) {
        specParams = specParams && specParams.algorithm ? specParams : SpecParams.getDefaultParams(); //默认值
        this.aesAlgo = specParams.algorithm;
    }
    /**
     * 使用Pbkdf2算法加密
     * @param base64Str base64字符串
     * @param cipher 公钥
     * @returns 加密数据
     */
    public encryptWithPbkdf2key(base64Str, cipher): string {
        return ecdh.hexToBase64(ecdh.encrypt(base64Str, cipher).toString('hex'));
    }
    /**
     * 使用Pbkdf2算法解密
     * @param encryptedText 加密数据
     * @param cipher 私钥
     * @returns base64字符串
     */
    public decryptWithPbkdf2key(encryptedText, cipher): string {
        return ecdh.decrypt(new Buffer(encryptedText, 'base64'), cipher); //解密文件内容
    }
}

export default AESCrypto;
